import { BasicColumn, FormProps } from '@/components/Table';
import { formatToDate } from '@/utils/dateUtil';
import { FormSchema } from '@/components/Form';
import { getLabelByValue, exerciseFrequencyOption, exerciseTypeOption } from './help/dict';
import { uploadApi, getPhotoUrl } from '@/api/sys/upload';

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      {
        field: `field11`,
        label: `Slot示例`,
        // component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}

/**
 * 配置表格SearchForm字段
 */
export const formConfig: Partial<FormProps> = {
  labelWidth: 100,
  baseColProps: {
    span: 8,
  },
  schemas: [
    {
      field: 'title',
      label: '课程名',
      component: 'Input',
    },
    {
      field: 'type',
      label: '锻炼类型',
      component: 'Select',
      componentProps: {
        options: exerciseTypeOption,
      },
    },
  ],
};

/**
 * 配置表格表头字段
 */
export const columns: BasicColumn[] = [
  {
    title: 'ID',
    width: 200,
    dataIndex: 'id',
    defaultHidden: true,
  },
  {
    title: '教练',
    width: 200,
    dataIndex: 'jlUid',
    defaultHidden: true,
  },
  {
    title: '用户',
    width: 200,
    dataIndex: 'uid',
    defaultHidden: true,
  },
  {
    title: '课程名',
    width: 200,
    dataIndex: 'title',
  },
  {
    title: '课程封面',
    width: 200,
    dataIndex: 'dataId',
    customRender: ({ record }) => {
      return <img width={100} src={`${getPhotoUrl}${record.dataId}`}></img>;
    },
  },
  {
    title: '锻炼类型',
    width: 200,
    dataIndex: 'type',
    customRender: ({ record }) => getLabelByValue(record.type, exerciseTypeOption),
  },
  {
    title: '锻炼频率',
    width: 200,
    dataIndex: 'frequency',
    customRender: ({ record }) => getLabelByValue(record.frequency, exerciseFrequencyOption),
  },
  {
    title: '锻炼时长(分钟)',
    width: 200,
    dataIndex: 'duration',
  },
  {
    title: '制定日期',
    width: 200,
    dataIndex: 'createTime',
    customRender: ({ record }) => formatToDate(record.createTime),
    defaultHidden: true,
  },
  {
    title: '备注内容',
    width: 200,
    dataIndex: 'context',
  },
];

/**
 * form配置
 */
export const schemas: FormSchema[] = [
  {
    field: 'id',
    component: 'Input',
    label: 'ID',
    colProps: {
      span: 20,
    },
    componentProps: {
      disabled: true,
    },
    ifShow: false,
  },
  {
    field: 'jlUid',
    component: 'Input',
    label: '教练',
    colProps: {
      span: 20,
    },
    componentProps: {
      disabled: true,
    },
    ifShow: false,
  },
  {
    field: 'title',
    component: 'Input',
    label: '课程名',
    colProps: {
      span: 20,
    },
    rules: [{ required: true, message: '课程名不能为空' }],
  },
  {
    field: 'dataId',
    component: 'ImageUpload',
    label: '课程封面',
    colProps: {
      span: 20,
    },
    // rules: [{ required: true, message: '请上传课程封面' }],
    componentProps: {
      api: uploadApi,
    },
  },
  {
    field: 'type',
    component: 'Select',
    label: '锻炼类型',
    colProps: {
      span: 20,
    },
    componentProps: {
      options: exerciseTypeOption,
    },
    rules: [{ required: true, message: '锻炼类型不能为空' }],
  },
  {
    field: 'frequency',
    component: 'Select',
    label: '锻炼频率',
    colProps: {
      span: 20,
    },
    componentProps: {
      options: exerciseFrequencyOption,
    },
  },
  {
    field: 'duration',
    component: 'InputNumber',
    label: '锻炼时长',
    colProps: {
      span: 20,
    },
    componentProps: {
      addonAfter: '分钟',
    },
  },
  {
    field: 'context',
    component: 'InputTextArea',
    label: '备注内容',
    colProps: {
      span: 20,
    },
  },
];

/**
 * table数据
 * @returns
 */
export function initData() {
  return [
    {
      id: '1',
      jlUid: '1',
      title: '增肌计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/8c7b47fe496417d779dd21042b8508b0.jpg',
      type: '0',
      frequency: '0',
      duration: '10',
      createTime: '20200701',
      context: '增肌计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
    {
      jlUid: '1',
      title: '跑步计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/128b08805076d7eab6e3e96c872377aa.jpg',
      type: '1',
      frequency: '1',
      duration: '10',
      createTime: '20200701',
      context: '跑步计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
    {
      jlUid: '1',
      title: '跳神计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/128b08805076d7eab6e3e96c872377aa.jpg',
      type: '1',
      frequency: '0',
      duration: '10',
      createTime: '20200701',
      context: '跳神计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
    {
      jlUid: '1',
      title: '睡眠计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/128b08805076d7eab6e3e96c872377aa.jpg',
      type: '4',
      frequency: '2',
      duration: '10',
      createTime: '20200701',
      context: '睡眠计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
    {
      jlUid: '1',
      title: '瑜伽计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/a7d73ec8ba3962f8ab48e77362958474.jpg',
      type: '3',
      frequency: '3',
      duration: '10',
      createTime: '20200701',
      context: '瑜伽计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
    {
      jlUid: '1',
      title: '体测速成计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/128b08805076d7eab6e3e96c872377aa.jpg',
      type: '2',
      frequency: '0',
      duration: '10',
      createTime: '20200701',
      context: '体测速成计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
    {
      jlUid: '1',
      title: '21天猛男计划',
      dataId: 'https://www.lesmills.com.cn/uploads/20211207/128b08805076d7eab6e3e96c872377aa.jpg',
      type: '2',
      frequency: '0',
      duration: '10',
      createTime: '20200701',
      context: '21天猛男计划，适合所有肌肉群，包括小腿、大腿、手臂、背部等。',
    },
  ];
}
